<?php
/**
 * Yii view _filter
 *
 * @author nguyenmanhluu
 * @since Aug 26, 2013 - 8:10:32 PM
 */
?>
<form method="GET">
    <div class="pull-left"> 
        <?php
        if ($this->isAdmin)
        {

            $bizTitle    = array('0' => 'Select Business');
            $bizArray    = $bizTitle + Users::getAllBussiness(TRUE);
            echo CHtml::dropDownList('business', $this->filterBusiness, $bizArray, array(
                'onchange' => 'load_select_staff();'
            ));
            ?>
            &nbsp;
            <?php
            $biz_ukey    = isset($_GET['business']) ? $_GET['business'] : '';
            $staffTitle  = array('0' => 'Select Staff');
            $staff_array = $staffTitle + Users::getAllStaffByBusiness($biz_ukey, TRUE);
            echo CHtml::dropDownList('staff', $this->filterStaff, $staff_array);
        }
        ?>
        &nbsp;
        <?php
        if ($this->isBussiness)
        {
            $staffTitle = array('0' => 'Select Staff');
            $biz_ukey   = Users::getUkeyById(Yii::app()->user->id);
            $staffArray = $staffTitle + Users::getAllStaffByBusiness($biz_ukey, TRUE);
            echo CHtml::dropDownList('staff', $this->filterStaff, $staffArray);
        }
        ?>
    </div>
    <div class="pull-left">
        <?php
        echo CHtml::submitButton('Submit', array(
            'class' => 'btn btn-success'
        ))
        ?>
    </div>
    <div class="clearfix"></div>
</form>

<script>
    function load_select_staff() {
        $.post('<?php echo Yii::app()->createUrl('Appointment/GetStaffbyBizUkey'); ?>', {
            loadStaffList: 'yes',
            biz_ukey: $("#business").val()
        }, function(data) {
            if (typeof (data) == 'object') {
                listStaff = [];
                listStaff = data;
                show_select_staff();
            } else {
                alert(data);
            }
        }, 'json');
        return false;
    }

    function show_select_staff() {
        var str = '';
        str += '	<option value="0">Select Staff</option>';
        if (listStaff.length > 0) {
            for (var i = 0; i < listStaff.length; i++) {
                str += '<option value="' + listStaff[i].staff_ukey + '">' + listStaff[i].staff_name + '</option>';
            }
        }
        $("#staff").empty().append(str);
        $("#staff").val(0);
    }
</script>